package com.example.news.controller;


import com.example.news.pojo.entity.Category;
import com.example.news.pojo.form.BasePageQuery;
import com.example.news.pojo.form.CategoryForm;
import com.example.news.pojo.vo.CategoryVo;
import com.example.news.service.CategoryService;
import com.example.news.utils.result.PageResult;
import com.example.news.utils.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "4.类型模块")
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    CategoryService categoryService;

    //类别创建
    @PostMapping("/create")
    @Operation(summary = "创建一个新闻类型")
    public Result<String>createCategory(@RequestBody CategoryForm categoryForm){
        return categoryService.createCategory(categoryForm);
    }

    //获取所有类别
    @GetMapping("/all")
    @Operation(summary = "获取所有新闻类型")
    public PageResult<CategoryVo>getAllCategory(@ParameterObject BasePageQuery basePageQuery){
        return categoryService.getAllCategory(basePageQuery);
    }

    @GetMapping("/user/all")
    @Operation(summary = "用户获取所有新闻类型")
    public PageResult<Category>userGetAllCategory(@ParameterObject BasePageQuery basePageQuery){
        return categoryService.userGetAllCategory(basePageQuery);
    }

    //修改类别
    @PostMapping("/modify")
    @Operation(summary = "修改新闻类型名称")
    public Result<String>modifyCategory(@RequestBody CategoryForm categoryForm){
          return categoryService.modifyCategory(categoryForm);
    }

    //删除类别
    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除新闻类型")
    public Result<String>deleteCategoryById(@PathVariable Integer id){
        return categoryService.deleteCategory(id);
    }
}